package com.example.myapplication9_5;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {
    private EditText et_username, et_nickname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        et_username = findViewById(R.id.et_username);
        et_nickname = findViewById(R.id.et_nickname);

        findViewById(R.id.btn_login).setOnClickListener(v -> {
            String name = et_username.getText().toString().trim();
            String nickname = et_nickname.getText().toString().trim();

            if (name.isEmpty() || nickname.isEmpty()) {
                Toast.makeText(this, "请填写完整信息", Toast.LENGTH_SHORT).show();
                return;
            }

            Intent resultIntent = new Intent();
            resultIntent.putExtra("uName", name);
            resultIntent.putExtra("uNickname", nickname);
            setResult(RESULT_OK, resultIntent);
            finish();
        });
    }
}
